﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class QuanLyKhachSan_DiemThamQuanCuaTuyen : Form
    {
        public QuanLyKhachSan_DiemThamQuanCuaTuyen()
        {
            InitializeComponent();
        }
        public void Showmaster1()
        {
            int MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            this.dgvKhachSan.AutoGenerateColumns = true;
            this.dgvKhachSan.DataSource = KHACHSAN_BUS.SelectKhachSansByAndMaTP(MaTP);
        }
        public void Showmaster2()
        {
            int MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            this.dgvDanhSachDD.AutoGenerateColumns = true;
            this.dgvDanhSachDD.DataSource = DDTQ_BUS.SelectDDTQsByAndMaTP(MaTP);
        }
        private void QuanLyKhachSan_DiemThamQuanCuaTuyen_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = THANHPHO_BUS.SelectThanhPhosAll();
            comboBox1.ValueMember = "MaTP";
            comboBox1.DisplayMember = "TenTP";
            int MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            this.dgvDanhSachDD.DataSource = DDTQ_BUS.SelectDDTQsByAndMaTP(MaTP);
            //this.dgvKhachSan.AutoGenerateColumns = true;
            this.dgvKhachSan.DataSource = KHACHSAN_BUS.SelectKhachSansByAndMaTP(MaTP);
           // this.dgvDanhSachDD.AutoGenerateColumns = true;
           
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           comboBox1.ValueMember = "MaTP";
           int MaTP = int.Parse(comboBox1.SelectedValue.ToString());
           //this.dgvKhachSan.AutoGenerateColumns = true;
           this.dgvKhachSan.DataSource = KHACHSAN_BUS.SelectKhachSansByAndMaTP(MaTP);
           this.dgvDanhSachDD.DataSource = DDTQ_BUS.SelectDDTQsByAndMaTP(MaTP);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ThemTP themTP = new ThemTP();
            themTP.ShowDialog();
            comboBox1.DataSource = THANHPHO_BUS.SelectThanhPhosAll();
            comboBox1.ValueMember = "MaTP";
            comboBox1.DisplayMember = "TenTP";
        }
        private void btThemKS_Click(object sender, EventArgs e)
        {
             KHACHSAN_DTO ks = new KHACHSAN_DTO();
             ks.MaTP = int.Parse(comboBox1.SelectedValue.ToString());
             ks.TenKS = textBox2.Text;
             ks.TienPhong = float.Parse(textBox3.Text.ToString());
             bool result = KHACHSAN_BUS.ThemKhachSan(ks);
             MessageBox.Show("Successful!", "Insert", MessageBoxButtons.OK, MessageBoxIcon.Information);
            textBox1.Text = ks.MaKS.ToString();
            // this.textBox1.Text = this.dgvKhachSan.CurrentRow.Cells["MaKS"].Value.ToString();
             Showmaster1();
           
        }
        private void btSuaKS_Click(object sender, EventArgs e)
        {
            KHACHSAN_DTO ks = new KHACHSAN_DTO();
            ks.MaKS = int.Parse(textBox1.Text);
            ks.MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            ks.TenKS = textBox2.Text;
            ks.TienPhong = float.Parse(textBox3.Text.ToString());
            if(ks.MaKS!=0)
            {
                KHACHSAN_BUS.SuaKhachSan(ks);
                MessageBox.Show("Successful!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Showmaster1();
            }
            else
            {
                MessageBox.Show("Fail!\r\nCoi Lại Mã UPDATE !\n Chọn Dữ Liệu UPDATE!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            
            }
        }

        private void btXoaKS_Click(object sender, EventArgs e)
        {
            KHACHSAN_DTO ks = new KHACHSAN_DTO();
            ks.MaKS = int.Parse(textBox1.Text);
            
            if(ks.MaKS!=0)
            {
                DialogResult dr = MessageBox.Show("bạn muốn xóa khách sạn có mã  " + ks.MaKS + "?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dr == DialogResult.Yes)
                {

                    KHACHSAN_BUS.XoaKhachSan(ks.MaKS);
                    MessageBox.Show("Successful!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Showmaster1();   
                }
            }
            else
            {
                MessageBox.Show("Fail!\r\nCoi Lại Mã DELETE !\n Chọn Dữ Liệu DELETE!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
   
           
        }

        private void btDD_Click(object sender, EventArgs e)
        {
            DDTQ_DTO ddtq = new DDTQ_DTO();
            ddtq.MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            ddtq.TenDD = textBox5.Text;
            ddtq.GiaVeThamQuan = float.Parse(textBox6.Text.ToString());
            ddtq.ChiPhiAnUong = float.Parse(textBox7.Text.ToString());
            DDTQ_BUS.ThemDDTQ(ddtq);
            MessageBox.Show("Successful!", "Insert", MessageBoxButtons.OK, MessageBoxIcon.Information);
            textBox4.Text = ddtq.MaDD.ToString();
            Showmaster2();
        }

        private void btXoaDD_Click(object sender, EventArgs e)
        {
            DDTQ_DTO ddtq = new DDTQ_DTO();
            ddtq.MaDD= int.Parse(textBox4.Text);
            if (ddtq.MaDD!=0)
            {
                DialogResult dr = MessageBox.Show("bạn muốn xóa dia diem tham quan có mã  " + ddtq.MaDD + "?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
           
                if (dr == DialogResult.Yes)
                {
                    DDTQ_BUS.XoaDDTQ(ddtq.MaDD);
                    MessageBox.Show("Successful!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Showmaster2();
                }
            }
            else
            {
                MessageBox.Show("Fail!\r\nCoi Lại Mã DELETE !\n Chọn Dữ Liệu DELETE!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          
            }
        }
        private void btSuaDD_Click(object sender, EventArgs e)
        {
            DDTQ_DTO ddtq = new DDTQ_DTO();
            ddtq.MaDD = int.Parse(textBox4.Text);
            ddtq.MaTP = int.Parse(comboBox1.SelectedValue.ToString());
            ddtq.TenDD = textBox5.Text;
            ddtq.GiaVeThamQuan = float.Parse(textBox6.Text.ToString());
            ddtq.ChiPhiAnUong = float.Parse(textBox7.Text.ToString());
            if (ddtq.MaDD != 0)
            {
                DDTQ_BUS.SuaDDTQ(ddtq);
                MessageBox.Show("Successful!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Showmaster2();
            }
            else
            {
                MessageBox.Show("Fail!\r\nCoi Lại Mã UPDATE !\n Chọn Dữ Liệu UPDATE!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btThoat_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Bạn Thật Sự Muốn Thoát?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (dr == DialogResult.Yes)
            {
                this.Close();
            }

        }
        private void dgvKhachSan_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dgvKhachSan.CurrentRow != null)
            {
                this.textBox1.Text = this.dgvKhachSan.CurrentRow.Cells["MaKS"].Value.ToString();
                this.textBox2.Text = this.dgvKhachSan.CurrentRow.Cells["TenKS"].Value.ToString();
                this.textBox3.Text = this.dgvKhachSan.CurrentRow.Cells["TienPhong"].Value.ToString();

            }
        }
        private void dgvDanhSachDD_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dgvDanhSachDD.CurrentRow != null)
            {
                this.textBox4.Text = this.dgvDanhSachDD.CurrentRow.Cells["MaDD"].Value.ToString();
                this.textBox5.Text = this.dgvDanhSachDD.CurrentRow.Cells["TenDD"].Value.ToString();
                this.textBox6.Text = this.dgvDanhSachDD.CurrentRow.Cells["GiaVeThamQuan"].Value.ToString();
                this.textBox7.Text = this.dgvDanhSachDD.CurrentRow.Cells["ChiPhiAnUong"].Value.ToString();
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

       


      
    }
}
